
<template>
 <div>
   <div class="fixed top-0 right-0 w-full " style="z-index: 999">
      <MiniNav :winType="WindowsType.Message"></MiniNav>
   </div>

   <div class="mt-4 " >
     <MessageContent :ChatMessages="chatMessages"></MessageContent>
   </div>

   <div class="h-6">
   </div>

   <div>
     <MessageInput></MessageInput>
   </div>


 </div>
</template>
<script setup lang="ts">
import {onMounted, ref} from 'vue'
import {useWindowsStore, WindowsType} from "../store/windows";
import {dto} from "../../wailsjs/go/models";
import {GetMousePos} from "../../wailsjs/go/service/SystemService";
import MiniNav from "../components/MiniNav.vue";
import MarkdownIt from 'markdown-it';
import MessageContent from "../layout/MessageContent.vue";
import {SenderAI, SenderUser} from "../constant/sender";

import {SetPosByConfig, SetSizeByConfig} from "../utils/SetWinInfo";
import {ToastError} from "../utils/Toast";
import MessageInput from "../layout/MessageInput.vue";
import {useGlobalStore} from "../store/global";
import {GetDefaultTool} from "../../wailsjs/go/dbservice/UserToolService";
import {CreateChatDialog} from "../../wailsjs/go/dbservice/DbChatDialogService";
import {RespCodeOk} from "../constant/enums/RespCode";

let storeGlobal =ref(useGlobalStore())

onMounted(async () => {
   let size= await  SetSizeByConfig(WindowsType.Message)
   // await SetLocationByMouse(size.w,size.h)
  await SetPosByConfig(WindowsType.Message)
   let pos:dto.Pos = await GetMousePos()
   console.log(pos,"-----pos value")
   if(storeGlobal.value.CurrChatDialogId <= 0){
      GetDefaultTool().then(info=>{
        if(!info){
          ToastError("请先创建应用")
          return
        }
        if(info.id){
          storeGlobal.value.CurrChatToolInfo=info
          storeGlobal.value.CurrChatToolId=info.id
          CreateChatDialog(info.id,[]).then(res=>{
            if (res.code == RespCodeOk){
              storeGlobal.value.CurrChatDialogId=res.data
            }else{
              ToastError("对话创建失败"+res.msg)
            }
          })
        }

      })
   }
})



let avatarUrl ="https://thirdwx.qlogo.cn/mmopen/vi_32/MhjGDO7GveElcbyMG0OGicBr6mDzNrwbHibABmOIR6OftBnDVuGn7IJKg3v3QkKnnVpWOb3TIXibXYKAXfB6nTq8A/132"
let chatMessages= ref<Array<any>>(
    [
    { avatar: avatarUrl,  content: '你好呀', sender: SenderUser },
    { avatar: avatarUrl, content: '好呀', sender: SenderAI }
  ]
)


function  convertMarkdownToHTML(markdown:string):string {
  const md = new MarkdownIt();
  return md.render(markdown);
}

let storeWin=ref(useWindowsStore())




</script>
<style>
pre {
  background-color: #f4f4f4;
  border: 1px solid #ccc;
  padding: 10px;
  overflow: auto;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
}

pre code {
  display: block;
  color: #333;
  white-space: pre;
}
</style>